package com.itheima.test8;

import java.io.*;
import java.net.Socket;

/**
 * @Author:gy
 * @Date: 2025/09/04 11:39
 * @Description:
 */
public class ClientDemo {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1",10010);
        //客户端从本地读取一个文件,发送给服务端
        //获取本地的流  输入流  读取本地的文件
       BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\班级\\93期\\day14-网络编程&基础加强\\day14-网络编程&基础加强\\heima.jpg"));
        //将读到的文件写到服务器中   网络中的流
        OutputStream os = socket.getOutputStream();
        //包装成缓冲流
        BufferedOutputStream bos = new BufferedOutputStream(os);
        int b;
        while ((b = bis.read()) != -1) {
          bos.write(b);
        }
        bos.flush();
        //Read 阻塞的方法  给一个结束的标记
        socket.shutdownOutput();
        //接收服务端的反馈  网络中的 字节输入流--->字符流--->缓冲字符流
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
        bos.close();
        os.close();
        bis.close();
        socket.close();
    }
}
